package com.atguigu.lease.common.exceptions;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * projectName: com.atguigu.lease.common.exceptions
 *
 * @author: 赵伟风
 * description: 全局异常处理 | 声明式异常处理
 */

@RestControllerAdvice
public class GlobalExceptionHandler {


    /*
        public static <T> Result<T> build(String message,int code) {
            Result<T> result = new Result<>();
            result.setCode(code);
            result.setMessage(message);
            return result;
        }
     */
   @ExceptionHandler(LeaseException.class)
   public Result leaseExceptionHandler(LeaseException e){
       e.printStackTrace();
       int code = e.getCode();
       String message = e.getMessage();
       return  Result.build(message,code);
   }


    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        e.printStackTrace();
        Result<Object> fail = Result.fail();
        return fail;
    }

}
